/*----------------------------------------------------------------------------*/
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
/*----------------------------------------------------------------------------*/

char * add( char * lhs, char * rhs );

/*----------------------------------------------------------------------------*/

int main(void)
{

char n1[100], n2[100];

    cout << "\nEnter 1st number:\n";
    cin  >> n1;
    
    cout << "\nEnter 2nd number:\n";
    cin  >> n2;

    cout << n1 << " + " << n2 << " = " << add( n1, n2 );

getch();
return 0;
}

/*----------------------------------------------------------------------------*/

char * add( char * lhs, char * rhs )
{

unsigned int len1 = 0, len2 = 0;

while( lhs[len1] ) len1++;
while( rhs[len2] ) len2++;

unsigned int size = ( len1 > len2 ? len1 : len2 ) + 2;

char * ans = new char[size];

int j = len1-1,
    k = len2-1,
    num1  = 0,
    num2  = 0,
    sum   = 0, 
    carry = 0;

unsigned int w = size-1;

cout << endl
     << setw(w) << lhs << endl
     << setw(w) << rhs << endl << endl;

for( unsigned int i = 0 ; i < len1 || i < len2 ; i++ )
{
    num1 = ( j < len1 ) ? ( lhs[j--] - '0' ) : 0 ;
    num2 = ( k < len2 ) ? ( rhs[k--] - '0' ) : 0 ;

    sum  = carry + num1 + num2;

    if( sum >= 10 )
    {
        carry = 1;
        sum = sum - 10;
    } 
    else
    {
        carry = 0;
    }

    ans[i] = sum + '0';
}

ans[size-2] = carry ? ( carry + '0' ) : '\0';
ans[size-1] = '\0';

size -= (( ans[size-2] == '\0' )? 2 : 1 );

for( unsigned int start = 0, end = size-1; start < size/2 ; start++, end-- )
{
    const char temp       = ans[start];
               ans[start] = ans[end];
               ans[end]   = temp;
}

return ans;
}
/*----------------------------------------------------------------------------*/
